<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * CodeIgniter
 *
 * An open source application development framework for PHP 4.3.2 or newer
 *
 * @package		CodeIgniter
 * @author		ExpressionEngine Dev Team
 * @copyright	Copyright (c) 2008 - 2009, EllisLab, Inc.
 * @license		http://codeigniter.com/user_guide/license.html
 * @link		http://codeigniter.com
 * @since		Version 1.0
 * @filesource
 */
// ------------------------------------------------------------------------

/**
 * @package		CodeIgniter
 * @subpackage	Libraries
 * @author		AnhDT
 */
	class Fx_Grid_Block extends Fx_Mini_Block {
		
		protected $_maxRow = 100;
		protected $_maxColumn = 3;
		
		function __construct() {
			parent::__construct();
			$this->__init();
		}
		
		function addItem(Fx_Cell_Block $item) {
			if ($item->getId()) {
				if ($this->_maxRow <= count($this->_items)) {
					throw new Exception('Over Maximum Row: ' + $this->_maxRow);
					return;
				}
				$this->_items[$item->getId()] = $item;	
			}
			return $this;
		}
		
		function setMaxRow($maxRow) {
			if ($maxRow >= 1) {
				$this->_maxRow = (int)$maxRow;
				return $this;	
			}
			return false;
		}
		
		function setMaxColumn($maxColumn) {
			if ($maxColumn >= 1) {
				$this->_maxColumn = (int)$maxColumn;
				return $this;	
			}
			return false;
		}
		
		function getMaxRow() {
			return (int)$this->_maxRow;	
		}
		
		function getMaxColumn() {
			return (int)$this->_maxColumn;	
		}
		
		function getOutputHtml() {
			 $_collectionSize = count($this->_items); 
			 $_columnCount    = $this->_maxColumn; 
			 $i = 0; 
			 $output = "<div class=\"blockMini block clear\" style=\"width: 100%\">\n" .
					   "<div class=\"blockHeader block clear\">\n".
					   "<div class=\"blockHeaderLeft left\">\n".
					   "<h4 class=\"headerTitle\">$this->_header</h4>\n".
					   "</div>\n".
					   "<div class=\"blockHeaderRight left\">\n".
					   "<a class=\"utilButton expButton\" id=\"expButton\" href=\"#\"></a>\n".
					   "</div>\n".
					   "</div>\n".
					   "<div class=\"blockContent block clear\">\n".
					   "<table width=\"100%\" border=\"1\">\n";
			 foreach ($this->_items as $_id => $_item) {
				 if ($i++%$_columnCount==0) { 
					$output .= "<tr class=\"items-grid\">\n";
				 }
					$output .= "<td width=\"80px\" colspan=\"1\" id=\"$_id\">\n";
					$output .= $_item->getOutputHtml() . "\n";
					$output .= "</td>\n";
				 if ($i%$_columnCount==0 || $i==$_collectionSize) { 
					$output .= "</tr>\n";
				 }
			 }
			 $output .= "</table>\n".
			 			"</div>\n".
					    "</div>\n";
			 return $output;
		}
		
		function __init() {return $this;}
	}
?>
